/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2019-03-07 20:06:20
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-10 14:49:13
 */
import { observable, action } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx';
import * as Api from './../apis/recPostLogApi';

const { TableStore } = WeaTableNew;
class RecPostLogStore {
  @observable topTab = [];
  @observable selectedKey = '0';
  @observable logTable = {
    tableStore: new TableStore(),
  };
  @observable groupid = 'allLog';
  @observable SearchForm = new WeaForm();
  @observable showSearchAd = false;
  // 切换页签
  @action.bound changeDate(v) {
    this.selectedKey = v;
    for (let list of this.topTab) {
      if (list.viewcondition == v) {
        this.groupid = list.groupid;
      }
    }
    this.getLogTableData();
  }
  // 获取tab页签
  @action.bound getTabData() {
    Api.getTabData().then((data) => {
      this.topTab = data.topTab;
    });
  }
  // 获取初始table
  @action.bound getLogTableData() {
    const params = { groupid: this.groupid };
    Api.getLogTableData(params).then((data) => {
      if (data.sessionkey) {
        this.logTable.tableStore.getDatas(data.sessionkey, 1, 10);
      }
    });
  }
  // 获取高级搜索的form
  @action.bound getSearchForm() {
    Api.getSearchForm().then((data) => {
      this.SearchForm.setCondition(data.items);
    });
  }
  // 高级搜索
  @action.bound getSearchData() {
    let formData = this.SearchForm.getFormParams();
    const params = {
      operatorId: formData.operatorId || '', // 操作者
      operationType: formData.operationType || '', // 操作类型
      optionsDate: formData.optionsDate || '', // 操作时间id
      startDate: formData.startDate || '', // 开始时间
      endDate: formData.endDate || '', // 结束时间
    };
    Api.getLogTableData(params).then((data) => {
      if (data.sessionkey) {
        this.logTable.tableStore.getDatas(data.sessionkey, 1, 10);
        this.showSearchAd = false;
        this.selectedKey = '0';
      }
    });
  }
  // 点击高级搜索
  @action.bound showtTag(bool) {
    this.showSearchAd = bool;
  }
}
export default new RecPostLogStore();
